layui.use(['form', 'layer','laydate','upload'], function(){
	  var form = layui.form
	  ,layer = layui.layer
	  ,laydate = layui.laydate
	  ,upload = layui.upload
	  ,$ = layui.$;
	  
		//得到用户类型
		var usersType = getParameter("usersType");
		//得到action
		var action = getParameter("action");
		$("#usersType").val(usersType);
		if(usersType == "2"){
			$("#sjmc").removeAttr("style");
		}
		if(action == 'update'){
			var usersId = getParameter("usersId");
			var data = {"usersId":usersId};
			var url = "../../user/findById.action";
			$.ajax({
				url:url,
				data:data,
				success:function(msg){
					form.val("myform", {
						  "usersId": msg.usersId
						  ,"usersName": msg.usersName
						  ,"usersPassword": msg.usersPassword
						  ,"usersImage": msg.usersImage
						  ,"businessName": msg.businessName
						})
						$('#demo1').attr('src', "../../"+msg.usersImage); //图片链接（base64）
				}
			});
		}
	  
	//普通图片上传
	  var uploadInst = upload.render({
	    elem: '#test1'
	    ,url: '../../upload/uploadFile.action'
	    ,accept: 'images'
	    ,choose: function(obj){
	    	//预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
	        obj.preview(function(index, file, result){
	          $('#demo1').attr('src', result); //图片链接（base64）
	        });
	    }
	    ,done: function(res){
	      $("#usersImage").val(res.url);
	    }
	    ,error: function(){
	      //演示失败状态，并实现重传
	      var demoText = $('#demoText');
	      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
	      demoText.find('.demo-reload').on('click', function(){
	        uploadInst.upload();
	      });
	    }
	  });
	  
	  form.on('submit(userAdd)', function(data){
		  parent.location.reload();//父页面刷新
	});
	
	});